package com.yinhai.shiro_demo.shiro;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class MyShiroRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        UsernamePasswordToken token = (UsernamePasswordToken) authenticationToken;
        String name = token.getUsername();
        //加入数据库的情况
        //根据用户名去数据库查询一次
        //User user = userService.findUserByUsername(name);
        //这个判断删除 if (user.getUsername.equals(name)) {
        if ("admin".equals(name)) {

           // return new SimpleAuthenticationInfo(user, user.getPassword, getName());
            return new SimpleAuthenticationInfo(name, "123456", getName());
        } else {
            return null;
        }
    }
}
